/*

Author   : chaos

FileName : dyn_2d_array.cpp

Date     : 10/08/17 10:49:58

*/
#include <iostream>
using namespace std;

int main(int argc ,char *argv[])
{
    int string_size;
    int n,i;

    cout <<" Please enter string number: " << endl;
    cin >> n;

    char ** ptr = new char *[n];

    cout << "The value of ptr :" << ptr << "address :" <<  &ptr << endl;

    for (i=0;i <n ;i++)
    {
        do {
            cout << "Please input the size of string " << (i+1) << "(size >0) :";
            cin >> string_size;

            if(string_size <=0)
                cout << "Error ! The size must be larger than zero!";
            cout << endl << "Input again ....." << endl;
        }
        while (string_size <=0);

        *(ptr+i) = new char [string_size + 1];
        for(int j=0;j <string_size; j++){
            *(*(ptr + i) +j) = char(65 + j);
        }
        *(*(ptr + i) + string_size) = '\0';
    }

    cout << "Address\t\t ( Value" << endl;
    cout << "-----------------------------------" << endl;

    for(i=0;i<n;i++)
    {
        cout <<&ptr[i];
        cout << "\t|" << (void*) ptr[i];
        cout << endl;
    }

    cout << endl << "Address \t\t| string" << endl;
    cout << "----------------------------" << endl;

    for (i=0;i<n;i++){
        cout << (void*)ptr[i] <<"\t|" << ptr[i];
        cout <<  endl;
    }

    for(i = 0; i < n; i++){
        delete[] ptr[i];
    }

    delete [] ptr;

    return 0;
}
